package com.burgeon.backend.Controller;


import com.burgeon.backend.entity.BatchCouponState;
import com.burgeon.backend.entity.CouponType;
import com.burgeon.backend.entity.VipAttrib;
import com.burgeon.backend.entity.VipQuery;
import com.burgeon.backend.service.CouponService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("coupon")
public class CouponController extends BaseController {

    @Autowired
    private CouponService couponService;

    //兑换购物券
    @RequestMapping("conversion")
    public ResponseResult<Void> Conversion(String tid, HttpSession session) {
        String token = session.getAttribute("token").toString();
        String phone = session.getAttribute("phone").toString();
        couponService.PointsAreRedeemedForCoupons(tid,phone,token);
        return new ResponseResult<>(SUCCESS);
    }

    //显示兑换
    @RequestMapping("showconversion")
    public ResponseResult<List> ShowConversion(HttpSession session) {
        String token = session.getAttribute("token").toString();
        List data = couponService.showRedeemCoupons(token);
        return new ResponseResult<>(SUCCESS, data);
    }

    @PostMapping("senddata")
    public ResponseResult<Void> SendData(@RequestParam("data") ArrayList<String> data, String flag, String account, String id) {


        couponService.batchAddThisCoupon(id, data, flag,account);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("query")
    public ResponseResult<List> Query(VipQuery query, String account) {

        System.err.println(query);
        List data = couponService.Query(query,account);

        return new ResponseResult<>(SUCCESS, data);
    }

    @RequestMapping("querytags")
    public ResponseResult<List> QueryTags(VipAttrib query, String account) {

        List data = couponService.QueryTags(query,account);
        return new ResponseResult<>(SUCCESS, data);
    }

    @RequestMapping("getbatch")
    public ResponseResult<BatchCouponState> GetBatchState(String account) {

        BatchCouponState data = couponService.GetBatchState(account);
        return new ResponseResult<BatchCouponState>(SUCCESS, data);
    }

    @RequestMapping("batchbytags")
    public ResponseResult<Void> BatchAddCouponByTags(String tid, VipAttrib query, String account) {

        couponService.batchAddCouponByTags(tid, query, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("batch")
    public ResponseResult<Void> BatchAddCoupon(String tid, VipQuery query, String account) {

        couponService.batchAddCoupon(tid, query, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("add")
    public ResponseResult<Void> AddCouponData(String id, String phone, String account) {

        couponService.addCoupon(id, phone, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("get")
    public ResponseResult<Map> GetCouponData(String start, String account) {

        HashMap data = couponService.getCoupon(start, account);
        return new ResponseResult<Map>(SUCCESS, data);
    }

    @RequestMapping("del")
    public ResponseResult<Void> DelCouponData(String id, String account) {

        couponService.delCoupon(id, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("gettype")
    public ResponseResult<List> GetCouponTypeData(String account) {

        List<CouponType> data = couponService.getCouponType(account);
        return new ResponseResult<List>(SUCCESS, data);
    }

    @RequestMapping("modtype")
    public ResponseResult<Void> ModCouponTypeData(CouponType couponType) {
        couponService.modCouponType(couponType);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("deltype")
    public ResponseResult<Void> DelCouponTypeData(String id) {
        couponService.delCouponType(id);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("addtype")
    public ResponseResult<Void> AddCouponTypeData(CouponType couponType, String account) {

        couponService.addCouponType(couponType, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("findtype")
    public ResponseResult<CouponType> FindCouponTypeData(String id) {
        CouponType data = couponService.findCouponType(id);
        return new ResponseResult<CouponType>(SUCCESS, data);
    }


}
